<?php

namespace app\admin\controller\yalimedia;

use app\common\controller\Backend;

use app\admin\model\AdCate;

/**
 * 轮播图
 *
 * @icon fa fa-circle-o
 */
class Ad extends Backend
{

    protected $model = null;
    protected $modelCate = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new  \app\admin\model\yalimedia\Ad();

        $this->modelCate = new  \app\admin\model\yalimedia\AdCate();
        
        $categorylist = $this->modelCate->order('weigh','desc')->select();
        $this->view->assign("parentList", $categorylist);
    }

 
    public function index()
    {
        $this->relationSearch = true;
        $this->searchFields = "admin.username,id";
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
           
            $list = $this->model
                ->with("adCate")
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }

}
